package com.wuliwu.autoapi.controller;

import com.wuliwu.autoapi.annotation.Desc;
import com.wuliwu.autoapi.annotation.Return;
import com.wuliwu.autoapi.bean.Result;
import com.wuliwu.autoapi.bean.User;
import com.wuliwu.autoapi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Desc("查询用户列表")
    @GetMapping("/list")
    @Return(User.class)
    public Result list(@Desc("用户名") String username){
        List<User> users = userService.list(username);
        return Result.success(users);
    }

    @Desc("新增用户")
    @GetMapping("/add")
    public Result add(@Desc("用户") User user){
        System.out.println(user);
        return Result.success();
    }

    @Desc("导入用户")
    @PostMapping("/import")
    public Result importUser(@Desc("类型") @RequestParam String type,
                             @Desc("文件") @RequestParam MultipartFile file){
        System.out.println(type);
        System.out.println(file.getName());
        return Result.success();
    }
}
